<template>
  <div>
    <!--  -->
    <!-- <div v-if="typeShow=='dept'">
        <treeselect
            v-model="deptId"
            :options="deptOptions"
            :disabled="disabled"
            noResultsText="暂无数据"
            :clearable='clearable'
            :normalizer="normalizer"
            placeholder="选择所属部门"
            class="treeselect-main"
        />
    </div> -->

    <div v-if="typeShow == 'duty'">
      <el-select
        :readonly="disabled"
        :disabled="disabled"
        filterable
        v-model="duty"
        placeholder="请选择"
        clearable
      >
        <el-option
          v-for="(item, index) in listUser"
          :key="index"
          :label="item.nickName"
          :value="item.userId"
        />
      </el-select>
    </div>
  </div>
</template>



<script>
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  data() {
    return {
      duty: "",
      deptOptions: [], //部门列表
    };
  },
  watch: {
    // 操作部门发生变化，清空人员input的回显值 重新请求人员列表
    deptId: {
      handler(val) {
        this.dutyId = null;
        // this.getlistUser(val);
        this.$emit("deptChange", val);
      },
      immediate: true,
    },

    // 操作
    duty: {
      handler(val) {
        this.duty = val;
        let data = {
          val,
          type: this.typeProp,
        };
        this.$emit("dutyChange", data);
      },
      immediate: true,
    },
  },
  model: {
    prop: "dutyId",
  },
  props: {
    typeShow: {
      type: String,
      default: "dept", //dept显示部门下拉框 duty显示人员下拉框 如果想使用部门联动人员，在人员引入是需要传部门id
    },
    disabled: {
      type: Boolean,
      default: false,
    },
    clearable: {
      type: Boolean,
      default: true,
    },
    listUser: {
      type: Array,
    },
    typeProp: {
      type: String,
    },
  },
  components: { Treeselect },
  created() {
    // this.init()
    // this.getlistUser();
  },
  methods: {
    /** 转换部门数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.deptId,
        label: node.deptName,
        children: node.children,
      };
    },
  },
};
</script>

<style>
</style>